import getCoupon from '../business/coupon/fetchGetCouponDataQuery.js';
import immutable from '../lib/immutable';
import { FAIL } from '../utils/fail';
const Coupon = {
    create: function create(config = {}) {
        const actionDispatcher = config.actionDispatcher;
        const onCoupon = config.onCoupon;
        const actionTypes = config.actionTypes || [];
        return {
            urlData: config.urlData || {},
            handle: function handle(event, params = immutable.fromJS({})) {
                if (!event || !event.toJS || !params.toJS) return;
                if (actionTypes.indexOf(event.get('id')) > -1) {
                    const token = params.get('token');
                    if (token) {
                        const coupon_id = event.get('value');
                        wx.showLoading();
                        actionDispatcher.execute(getCoupon, {
                            token,
                            coupon_id,
                        }, onCoupon);
                    } else {
                        onCoupon && onCoupon(FAIL, { token: undefined });
                    }
                }
            },
        };
    },
};
export default Coupon;
